%% Main supervisor
%% This should be started on the main node
-module(manager).
-behaviour(supervisor).
-behaviour(application).

%% supervisor exports
-export([init/1]).

%% application exports
-export([start/2, stop/1]).

%% supervisor
init({Size, UI}) ->
    RestartStrategy = {one_for_one, 5, 60},
    ChildSpecs = [
        {
            ui,
            {ui, start_link, [UI]},
            permanent,
            100,
            worker,
            [ui]
        },
        {
            trace_manager,
            {trace_manager, start_link, [Size]},
            permanent,
            100,
            worker,
            [trace_manager]
        }
    ],
    {ok, {RestartStrategy, ChildSpecs}}.

%% application
start(_StartType, _Args) ->
    {ok, Size} = application:get_env(def_size),
    {ok, Host} = application:get_env(ui_host),
    {ok, Port} = application:get_env(ui_port),
    supervisor:start_link({local, manager_supervisor}, manager, {Size, {Host, Port}}).

stop(_State) ->
    ok.

